package sparrowGui.skin
{
	import flash.display.Sprite;
	
	import sparrowGui.ComponentDraw;
	import sparrowGui.SparrowGUI;
	import sparrowGui.vars.ComponentVars;
	
	/**
	 * 四态按钮皮肤，普通状态、经过状态、按下状态、按下后状态、热区
	 * @author pelephone
	 */	
	public class TagsBtnSkin extends Sprite	
	{
		public var upState:Sprite;
		public var selectState:Sprite;
		public var overState:Sprite;
		public var downState:Sprite;
		public var hitTestState:Sprite;
		
		public function TagsBtnSkin()
		{
			init();
			addChildren();
		}
		
		protected function init():void
		{
			upState = new ComponentDraw(SparrowGUI.getIns().btn_up);
			upState.name = "upState";
			
			selectState = new ComponentDraw(SparrowGUI.getIns().btn_select);
			selectState.name = "selectState";
			
			overState = new ComponentDraw(SparrowGUI.getIns().btn_over);
			overState.name = "overState";
			
			downState = new ComponentDraw(SparrowGUI.getIns().btn_down);
			downState.name = "downState";
			
			hitTestState = null;
/*			hitTestState.graphics.beginFill(0xFF0000);
			hitTestState.graphics.drawRect(0,0,normalVar.width,normalVar.height);
			hitTestState.graphics.endFill();
			hitTestState.name = "hitTestState";*/
			
//			upState['forceDraw'] = selectState['forceDraw'] = overState['forceDraw'] = downState['forceDraw'] = true;
		}
		
		private function addChildren():void
		{
			if(upState) addChild(upState);
			if(selectState) addChild(selectState);
			if(overState) addChild(overState);
			if(downState) addChild(downState);
			if(hitTestState) addChild(hitTestState);
		}
		
		/**
		 * Sets/gets the width of the component.
		 */
		override public function set width(w:Number):void
		{
			upState.width = w;
			overState.width = w;
			downState.width = w;
			selectState.width	= w;
			if(hitTestState) hitTestState.width	= w;
		}
		
		/**
		 * Sets/gets the height of the component.
		 */
		override public function set height(h:Number):void
		{
			upState.height = h;
			overState.height = h;
			downState.height = h;
			selectState.height	= h;
			(upState as ComponentDraw).onInvalidate(null);
			(overState as ComponentDraw).onInvalidate(null);
			(downState as ComponentDraw).onInvalidate(null);
			(selectState as ComponentDraw).onInvalidate(null);
			if(!hitTestState) return;
			hitTestState.height = h;
			(hitTestState as ComponentDraw).onInvalidate(null);
		}
	}
}